#include <iostream>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    map<string, int> map_table;
    map_table["one"] = 1;
    map_table["two"] = 100;
    map_table.insert(pair<string, int>("three", 3));

    cout << "one key value is " << map_table["one"] <<endl;
    cout << "two key value is " << map_table["two"] <<endl;
    cout << "three key value is " << map_table["three"] <<endl;

    for (map<string,int> ::iterator it = map_table.begin(); it != map_table.end(); it++) {
        cout << "key is " << it->first << " value is " << it->second << endl;
    }

    multimap<char, int> my_multimap;
    multimap<char, int> ::iterator it;

    my_multimap.insert(pair<char, int> ('a', 10));
    // multimap允许一个键对应多个值
    my_multimap.insert(pair<char, int> ('b', 20));
    my_multimap.insert(pair<char, int> ('b', 30));
    my_multimap.insert(pair<char, int> ('b', 40));
    my_multimap.insert(pair<char, int> ('c', 30));
    


    for (it = my_multimap.begin(); it != my_multimap.end(); it++) {
        // cout << "key is " << it->first << " value is " << it->second << endl;
        cout << (*it).first << "=>" << (*it).second << endl;
    }
    cout << "key :" << my_multimap.find('a')->first << endl;
    cout << "value :" << my_multimap.find('a')->second << endl;



    cout << "---------" <<endl;

    pair<multimap<char, int> ::iterator, multimap<char,int> ::iterator> ret;
    ret = my_multimap.equal_range('b'); // 第一个迭代器指向第一个键为b的元素， 第二个迭代器指向最后一个键为b的元素
    for (it = ret.first; it != ret.second ; it++) {
        cout << (*it).second << endl;  //每个迭代器的元素值
    }
    return 0;
}
